/**
 * title: FEATURECONCEPTDAO_DeleteTestOneFeature.java
 * description: JUnit program that tests the FeatureConcept DAO.
 * date: December 29 2013
 * id: 2540434
 * course: COMP 495 (Project-Server)
 * @author Mohamed B Thaha
 * @version 1.0
 * @copyright 2013 Mohamed B Thaha
 */

/**
 * DOCUMENTATION...
 */

/**                                                                               
 *
 *<H1>FEATURECONCEPTDAO_DeleteTestOneFeature</H1>
 *
 *<H3>Purpose and Description</H3>
 *
 *<P>
 * An application that uses JUnit unit testing framework.
 *</P>
 *<P>
 * The program's main purpose is to provide sample test cases for specific CRUD
 * operations.
 *</P>
 *<P>
 * This program requires the Sun Java SDK version 1.7 or better.
 *</P>
 *                                                                              
 *<DL>
 *<DT> Compiling and running instructions</DT>
 *<DT> Assuming SDK 1.7 (or later) and the CLASSPATH are set up properly.</DT>
 *<DT> Assuming the use of Eclipse IDE (Kepler) 4.3.1.</DT>
 *<DT> Change to the directory containing the source code.</DT>
 *<DD> Compile:    FEATURECONCEPTDAO_DeleteTestOneFeature.java</DD>
 *<DD> Run:        FEATURECONCEPTDAO_DeleteTestOneFeature.java</DD>
 *<DD> Document:   Generate Javadoc FEATURECONCEPTDAO_DeleteTestOneFeature</DD>
 *</DL>
 */

/**
 *
 * <H3>Classes</H3>
 *
 *<P>
 * public class FEATURECONCEPTDAO_DeleteTestOneFeature {<BR>
 * This is the main public class for this application. It contains some of the
 * methods required to perform CRUD (test) operations.
 *</P>
 *
 * <H3>FEAUTURECONCEPTDAO_DeleteTestOneFeature Methods</H3>
 *
 *<P>
   public void setUp() {<BR>
   This method executes before the desired test method(s) runs; acts as a 
   preliminary setup method.
 *</P>
 *
 *<P>
   public final void testDeleteOneFeature ( ) {<BR>
   This method tests for a successful result provided that the 
   device id and feature name are correct.
 *</P>
 *
 *<P>
   public final void testDeleteOneFeatureFail ( ) {<BR>
   This method tests for a failed result provided that the 
   device id is correct but feature name is null.
 *</P>
 * 
 * <H3>FEATURECONCEPTDAO_DeleteTestOneFeature Instance Variables</H3>
 *
 *<P>
 * private Device device
 * private User user
 * private FeatureConcept feature
 * private static final long USER_ID = 54
 * private static final long DEVICE_ID = 900
 *</P>
 */

/**
 *
 * <H3>Test Plan</H3>
 *
 *<P>
 * public final void testDeleteOneFeature ( ) – OK
 * public final void testDeleteOneFeatureFail ( ) – OK
 *</P>
 */

/**
 * CODE...
 */

package athabasca.ca.dao.featureconcept;
/** Java core packages */
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import athabasca.ca.dao.DeviceDAO;
import athabasca.ca.dao.FeatureConceptDAO;
import athabasca.ca.model.Device;
import athabasca.ca.model.FeatureConcept;
import athabasca.ca.model.User;
/** primary (public) class for FEATURECONCEPTDAO_DeleteTestOneFeature */
public class FEATURECONCEPTDAO_DeleteTestOneFeature {
	private Device device;
	private User user;
	private FeatureConcept feature;
	private static final long USER_ID = 54;
    private static final long DEVICE_ID = 900;
	
	/**
	 *  The device ID and user ID must exist first in the device table
	 * @throws Exception
	 */
	@Before
	public void setUp() throws Exception {
		device = new Device(DEVICE_ID);
		user = new User(USER_ID);
		feature = new FeatureConcept ( "device_feature" );
		device.addFeature(feature);
		
		DeviceDAO.create(device, user.getUserId());
		
		FeatureConcept newFeature = new FeatureConcept("newFeature");
          
          try {
        	  FeatureConceptDAO.create(device.getDeviceId(), newFeature);
          } catch (Exception e)
          {
              fail ( e.getMessage ( ) );
              e.printStackTrace ( );
          }
	}
	
	@Test
	@Ignore
    public final void testDeleteOneFeature ( )
    {
  	  feature = new FeatureConcept ( "device_feature" );
  	  
  	  try {
      	  assertThat ( FeatureConceptDAO.delete(device.getDeviceId(), feature), is ( true ));
        } catch (Exception e)
        {
            fail ( e.getMessage ( ) );
            e.printStackTrace ( );
        }
    }
	
	@Test
	//@Ignore
    public final void testDeleteOneFeatureFail ( )
    {
  	  feature = new FeatureConcept ( null );
  	  
  	  try {
      	  assertThat ( FeatureConceptDAO.delete(device.getDeviceId(), feature), is ( false ));
        } catch (Exception e)
        {
            fail ( e.getMessage ( ) );
            e.printStackTrace ( );
        }
    }
} // End of public class FEATURECONCEPTDAO_DeleteTestOneFeature